import { app } from "../apiRoot";
import { defHttp } from '@/utils/http';
import type { IGetPhoneNumber, ILoginData, ILoginRes, UserInfoData, WxPhoneCodeLoginData } from "./types";
import { ThridTypeEnum } from "@/enums/LoginEnum";

const Api = {
  login: app + 'login/exc/wx/code/MINI',
  phoneNumber: app + 'login/phoneNumber/MINI',
  userInfoApi: app + 'login/getUserInfo',
  logOut: app + 'login/exit',
  wxPhoneCodeLogin: app + 'login/exc/wx/phone/verificationCode/MINI',
  getVerificationCode: app + 'login/exc/phone/getVerificationCode'
}

/**
 * 登录
 * @export
 * @param {ILoginData} data
 */
export function login(data: ILoginData) {
  return defHttp.post<ILoginRes>({
    url: Api.login,
    data,
  });
}

/**
 * @description 小程序授权手机号码
 * @date 16/10/2023
 * @export
 * @param {IGetPhoneNumber} data
 */
export function phoneNumberApi(data: IGetPhoneNumber) {
  return defHttp.post({
    url: Api.phoneNumber,
    data
  })
}

/**
 * @description 获取用户信息
 * @date 16/10/2023
 * @export
 */
export function userInfoApi() {
  return defHttp.post<UserInfoData>({
    url: Api.userInfoApi
  })
}

/**
 * @description 获取验证码
 * @date 19/03/2025
 * @export
 */
export function getVerificationCode(data: { phone: string, thridType: ThridTypeEnum }) {
  return defHttp.post<string>({
    url: Api.getVerificationCode,
    data
  })
}

/**
 * @description 微信小程序验证码登录
 * @date 19/03/2025
 * @export
 */
export function wxPhoneCodeLogin(data: WxPhoneCodeLoginData) {
  return defHttp.post({
    url: Api.wxPhoneCodeLogin,
    data
  })
}

/**
 * @description 退出登录
 * @date 06/03/2025
 * @export
 */
export function logOut() {
  return defHttp.post({
    url: Api.logOut,
  });
}
